<?php
class loginblock_chunk {
  function out(){
    global $user,$config,$document,$core;
	$facebook=$core->getApp("facebook");
    if ($user->id) {
      $plantilla= file_get_contents($config->paths["chunks/html"].'loginblock.1.html');
    }
    else {
      $plantilla= file_get_contents($config->paths["chunks/html"].'loginblock.2.html');
    }
	$fb_link=$facebook->getAuthURL($config->defaults["facebook"]->app_id,$config->paths["url"]."user/loginwithfacebook",$config->defaults["facebook"]->scope);
    $p=array(
      "#NOMBRE#"=>$user->get("nombre"),
      "#FB_LINK#"=>$fb_link,
	  "#EMAIL#"=>$_SESSION["fb_email"],
	  "#NOMBRE#"=>$_SESSION["fb_name"],
	  "#FB_LOGIN#"=>$user->get("fb_id")?"":'<a href="'.$fb_link.'"><img src="img/fb_connect.png"></a>',
	  "#TW_LINK#"=>$config->paths["url"]."user/gettwittertoken"
      );
	if($document){
		$document->addScript("js/login.js");
	}
    return str_replace(array_keys($p),$p,$plantilla);
  }
}
